package gx.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import gx.entity.Manager;
import gx.service.ManagerService;

@Controller
public class LoginCotroller {
    @Autowired
    private ManagerService managerService;
    @RequestMapping("/login.jhtml")
    public String login(String lname,String pwd,String cc,HttpSession session,HttpServletRequest request){
	
    	String result = "/login";
		String real_code= (String) session.getAttribute("real_code");
		//验证码是否正确
		if(cc != null && cc.equalsIgnoreCase(real_code)){
			//是否有该用户
			Manager manager = managerService.findLogin(lname);
			if(manager!=null){
				//密码
				if(manager.getPwd().equals(pwd)){
					//session中
					session.setAttribute("curr_mgr", manager);
					
					//登录成功
					result =  "redirect:/mng/main.jsp";
					
				}else{ 
					request.setAttribute("msg", "密码有误，请检查");
				}
			}else{
				request.setAttribute("msg", "用户有误，请检查");
			}
			
		}else{
			request.setAttribute("msg", "验证码不正确，请检查");
		}
		return result;
	}
	

}


